import com.thelab.ui.*;

dynamic class com.thelab.ui.Label extends UIElement
{	
	function Label(scope:MovieClip,str:String,px:Number,py:Number,input:Boolean,width:Number,height:Number)
	{					
		super("UILabel",scope);
		str = str || "";
		input = input || false;
		
		var tf:TextField = target;
		tf._x = px || 0;
		tf._y = py || 0;
		tf._width = width || 1;
		tf._height = height || 17;		
		tf.type = input ? "input" : "dynamic";
		
		if(input)
		{
			style.tfmultiline = false;
			style.fontalign = "left";
			style.tfborder = 0x333333;
			tf.border = style.tfborder>=0;
			tf.borderColor = style.tfborder;
			tf.background = style.tfbackcolor>=0;
			tf.backgroundColor = style.tfbackcolor;			
		}		
		tf.autoSize = (width==undefined) && (height==undefined);
		tf.multiline = style.tfmultiline;
		tf.selectable = input;	
		
		_label = str;		
	}
	
	function get _tWidth():Number  { return target.textWidth; }
	function get _tHeight():Number { return target.textHeight; }
	function set _tWidth(v:Number) { target.textWidth=v; }
	function set _tHeight(v:Number){ target.textHeight=v; }
	function get _label():String   { return target.text; }
	function set _label(str) { update_style(); target.text = String(str); }
	
	private function update_style(st:UIStyle)
	{	
		//trace("UILabel> Setting Style: ");
		//trace(style);
		var tf:TextFormat = target.getNewTextFormat();
		//trace((style.fontcolor>>16)+" "+((style.fontcolor&0x00ff00)>>8)+" "+(style.fontcolor&0x0000ff));
		tf.font =  style.font;
		tf.color = style.fontcolor;
		tf.size =  style.fontsize;
		tf.align = style.fontalign;	
		tf.bold = (style.fontcap.indexOf("b",0)>=0);
		tf.italic = (style.fontcap.indexOf("i",0)>=0);
		tf.underline = (style.fontcap.indexOf("u",0)>=0);
		target.border = style.tfborder>=0;
		target.borderColor = style.tfborder;
		target.background = style.tfbackcolor>=0;
		target.backgroundColor = style.tfbackcolor;
		target.multiline = style.tfmultiline;
		target.setNewTextFormat(tf);			
	}
	
	private function draw()
	{
		_label = _label;
	}	
	
	
}
